package org.ikastola

import ikastola.Constants;
import grails.plugins.springsecurity.Secured

@Secured(['ROLE_ADMIN'])
class DashboardController {

	
	def index(Integer max) {
		params.max = Math.min(max ?: 10, 100)
		[studentInstanceList: Student.findAllByDeleted(Constants.NOT_DELETED,params), studentInstanceTotal: Student.countByDeleted(Constants.NOT_DELETED)]
	}
	
	def search(Integer max) {
		params.max = Math.min(max ?: 10, 100)
		
		def studentInstanceList = Student.findAllByNameIlike('%'+params.query+'%')
		if(!studentInstanceList) {
			studentInstanceList = Student.findAllByLastnameIlike('%'+params.query+'%')
		}
		if(!studentInstanceList) {
			studentInstanceList = []
		}
		render(template: 'studentTable', model: [studentInstanceList: studentInstanceList, studentInstanceTotal: studentInstanceList.size])
	}
	
	def paginate(Integer max) {
		params.max = Math.min(max ?: 10, 100)
		render(template: 'studentTable', model: [studentInstanceList: Student.findAllByDeleted(Constants.NOT_DELETED,params), studentInstanceTotal: Student.countByDeleted(Constants.NOT_DELETED)])
	}
	
	def charge(Long id) {
		
	} 
}
